<script type="text/javascript">
	$(function() {
		var $table_id = $("#firm-post-list");
		var user = {
			getQueryCondition: function(data) {
				var param = {};
				param.costName = $.trim($("#costName").val());
				param.pageNumber = Number(data.start/data.length)+1  || 1;
				param.pageSize = data.length   || 15;
				param.state=$("#state").val();
				return param;
			}
		};
	    var dataTable = $table_id.DataTable({
            dom: '<".table_area_top" B and >t<".table_area_bottom" pi>',
            Filter: false, //列筛序功能
            searching: false,//本地搜索
            ordering: true, //排序功能
	    	"aaSorting":[[ 3, "asc" ]] ,
	    	"aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0,1,2] }]  ,
			
            Info: true,//页脚信息
            lengthMenu: [15],//定义每页显示数据数量
            scrollY: "auto",
            Paginate: true, //翻页功能
            sortable: false,
            processing: true,
            serverSide: true,
			ajax: function(data, callback) { //ajax配置为function,手动调用异步查询
				$.post("/guidance_service/front/data/dataList.do", user.getQueryCondition(data),function(result) {
						//封装返回数据，这里仅演示了修改属性名
						var returnData = {};
						returnData.recordsTotal = result.data.totalRow;
						returnData.recordsFiltered = result.data.totalRow; //后台不实现过滤功能，每次查询均视作全部结果
						returnData.data = result.data.list;
						callback(returnData);
				});
			},
			//使用对象数组，一定要配置columns，告诉 DataTables 每列对应的属性
			//data 这里是固定不变的，id，name，age，sex等为你数据里对应的属性
			columns: [
				{
					data: "costName",
					render: function(data, type, row) {
						return '<a style="text-decoration:none" class="ml-5" onClick="data_open(\''+data+'\',\'/admin/modules/datashare/info/infoList.html?costId=' 
						+ row.costId + '\')" href="javascript:;" title="查看详情">'+data+'</a>';
					}
				},
				{
					data: "catalogId", //
					render: function(data,type, row) {
						return data || "";
					}
				},
				{
					data: "address",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "totalArea",
					render: function(data, type, row) {
						return data || "";
					}
				},
				{
					data: "projectHeight", //
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "totalFloor", //
					render: function(data, type, row) {
						return data || "";
					}
				},
				{
					data: "createUserId",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "createTime",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "updateUserId",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "updateTime",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "state",
					render: function(data) {
						if ('0'==data) {
	                    	return '<span class="label label-primary  radius">待审核</span>';
	                    }else if('1'==data){
	                    	return '<span class="label label-success  radius">已审核</span>';
	                    }else if('2'==data){
	                    	return '<span class="label label-warning  radius">未通过</span>';
	                    }
					}
				}
			],
			language: { //国际语言转化
				aria: {
					sortAscending: " - click/return to sort ascending",
					sortDescending: " - click/return to sort descending"
				},
				lengthMenu: "显示 _MENU_ 记录",
				zeroRecords: "对不起，查询不到任何相关数据",
				emptyTable: "未有相关数据",
				loadingRecords: "正在加载数据-请等待...",
				info: "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录。",
				infoEmpty: "当前显示0到0条，共0条记录",
				infoFiltered: "（数据库中共为 _MAX_ 条记录）",
				processing: " 正在加载数据...",
				//多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
				paginate: {
					first: "首页",
					previous: " 上一页 ",
					next: " 下一页 ",
					last: " 尾页 "
				}
			},
			"drawCallback": function (settings) {
                var api = this.api();
            }
		});
		$("#searchButton").on("click", function () {
            dataTable.draw();
        });

        $("body").on("change", ":checkbox", function () {
            if ($(this).is("[name='checkBtn']")) {
                //全选
                $(":checkbox", $table_id).prop("checked", $(this).prop("checked"));
            } else {
                //一般复选
                var checkbox = $("tbody :checkbox", $table_id);
                $(":checkbox[name='checkBtn']", $table_id).prop('checked', checkbox.length == checkbox.filter(':checked').length);
            }
        }).on("click", ".td-checkbox", function (event) {
            //点击单元格即点击复选框
            !$(event.target).is(":checkbox") && $(":checkbox", this).trigger("click");
        })
	});
</script>